package org.xxl.views.base 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import org.osflash.signals.natives.sets.InteractiveObjectSignalSet;
	import org.xxl.views.core.IToggle;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class ToggleButton extends TempleteComponent implements IToggle 
	{
		private var _movie:MovieClip;
		private var _ioss:InteractiveObjectSignalSet;
		private var _selected:Boolean = false;
		
		public function ToggleButton() 
		{
			
		}
		
		override public function buildTemplete(skin:DisplayObject):void 
		{
			if (skin is MovieClip)
			{
				super.buildTemplete(skin);
				
				this._movie = skin as MovieClip;
				this._movie.gotoAndStop(1);
				this._movie.buttonMode = true;
				this._movie.mouseChildren = false;
				_ioss = new InteractiveObjectSignalSet(this._movie);
				_ioss.mouseOver.add(overOutHandler);
				_ioss.mouseOut.add(overOutHandler);
			}
			else
			{
				throw new Error("必须为MovieClip");
			}
		}
		
		private function overOutHandler(e:MouseEvent):void
		{
			if (_selected == false)
			{
				if (e.type == MouseEvent.MOUSE_OVER)
				{
					this._movie.gotoAndStop(2);
				}
				else if (e.type == MouseEvent.MOUSE_OUT)
				{
					this._movie.gotoAndStop(1);
				}
			}
		}
		
		/* INTERFACE org.xxl.views.core.IToggle */
		
		public function set selected(value:Boolean):void 
		{
			_selected = value;
			if (value)
			{
				this._movie.gotoAndStop(3);
			}
			else
			{
				this._movie.gotoAndStop(1);
			}
		}
		
		public function get selected():Boolean 
		{
			return _selected;
		}
		
	}

}